// 获取首页内容
export async function fetchHome({ dispatch, commit }) {
  const data = await dispatch('fetch', {
    url: '/api/hotel/v2/home'
  })
  const {
    article = {},
    banner = {},
    brand = [],
    guess = [],
    hotel = [],
    shop = {}
  } = data
  commit('home/SET_HOME', {
    article,
    banner,
    brand,
    guess,
    hotel,
    shop,
    data
  })
}

// 切换城市
export async function changeCity({ commit, state }, region_code) {
  const city = state.cityList.find(
    item => parseInt(item.region_code) === parseInt(region_code)
  )
  if (city) {
    commit('CHANGE_CITY', city)
  }
  return axios({
    url: '/web/api/change/city',
    method: 'post',
    data: { city }
  })
}
